Coding Interview Ninja: 50 coding questions with Java solutions to practice for your coding interview. by Ekim Ouye

Coding Interview Ninja: 50 coding questions with Java solutions to practice for your coding interview. by Ekim Ouye

Author:Ekim Ouye [Ouye, Ekim]
Language: eng
Format: epub
Tags: Computers & Technology
Published: 2015-03-28T07:00:00+00:00


AVERAGE RUNNING TIME COMPLEXITY:

O(N)

WORST RUNNING TIME COMPLEXITY:

O(N2)

SPACE COMPLEXITY:

O(1)

22.Given that a tree is a full binary tree (= every node other than the leaves has two children) and the pre-order and post-order traversal of the tree, re-construct it.

e.g:

input:

pre-order: 5, 3, 7

post-order: 3, 7, 5

output:

tree:

5

3 7

_______________

SOLUTION:

static int mPreIndex = 0;

public static TNode constructTree(int[] pre, int[] post, int lo, int hi) {

if ((lo > hi) || (mPreIndex >= pre.length)) {

return null;

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.